'use strict'

import fs from 'fs'
import path from 'path'
import mongoose from 'mongoose'



const db = 'mongodb://localhost/gougou-app'
mongoose.Promise = require('bluebird')
mongoose.connect(db)
const models_path = path.join(__dirname, '/app/models')

const walk = (modelPath) => {
  fs
    .readdirSync(modelPath)
    .forEach(file => {
      const filePath = path.join(modelPath, '/' + file)
      const stat = fs.statSync(filePath)

      if (stat.isFile()) {
        if (/(.*)\.(js|coffee)/.test(file)) require(filePath)
      } else if (stat.isDirectory()) {
        walk(filePath)
      }
    })
}

walk(models_path)



import Koa from 'koa'
import logger from 'koa-logger'
import session from 'koa-session'
import bodyParser from 'koa-bodyparser'

const app = new Koa()
app.keys = ['gougou']
app.use(logger())
app.use(session(app))
app.use(bodyParser())



const router = require('./config/routes')()
app
  .use(router.routes())
  .use(router.allowedMethods())




app.listen(3000)
console.log('Listening: 3000')